<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
if (!isset($_GET['oid']) || (int)$_GET['oid'] <= 0) {
	header('Location: index.php');
}

$orderId = (int)$_GET['oid'];

// get ordered items
$sql = "SELECT product_name, od_price
	    FROM " . TBL_ORDERS . " od, " . TBL_PRODUCTS . " p, " . TBL_AUCTIONS . " a  
		WHERE a.product_id = p.product_id AND a.auction_id = od.auction_id AND od.od_id = $orderId
		ORDER BY od_id ASC";

$result = execute_query($sql);
$orderedItem = array();
foreach ($result as $row) {
	$orderedItem[] = $row;
}

// get order information
$sql = "SELECT od_date, od_last_update, od_status, od_shipping_userkey
	    FROM " . TBL_ORDERS . " 
		WHERE od_id = $orderId";

$result = execute_query($sql);
extract($result[0]);

$orderStatus = array('New', 'Paid', 'Shipped', 'Completed', 'Cancelled');
$orderOption = '';
foreach ($orderStatus as $status) {
	$orderOption .= "<option value=\"$status\"";
	if ($status == $od_status) {
		$orderOption .= " selected";
	}
	
	$orderOption .= ">$status</option>\r\n";
}
?>
<p>&nbsp;</p>
<form action="" method="get" name="frmOrder" id="frmOrder">
    <table width="550" border="0"  align="center" cellpadding="5" cellspacing="1" class="detailTable">
        <tr> 
            <td colspan="2" align="center" id="infoTableHeader">Order Detail</td>
        </tr>
        <tr> 
            <td width="150" class="label">Order Number</td>
            <td class="content"><?php echo $orderId; ?></td>
        </tr>
        <tr> 
            <td width="150" class="label">Order Date</td>
            <td class="content"><?php echo $od_date; ?></td>
        </tr>
        <tr> 
            <td width="150" class="label">Last Update</td>
            <td class="content"><?php echo $od_last_update; ?></td>
        </tr>
        <tr> 
            <td class="label">Status</td>
            <td class="content"> <select name="cboOrderStatus" id="cboOrderStatus" class="box">
                    <?php echo $orderOption; ?> </select> <input name="btnModify" type="button" id="btnModify" value="Modify Status" class="box" onClick="modifyOrderStatus(<?php echo $orderId; ?>);"></td>
        </tr>
    </table>
</form>
<p>&nbsp;</p>
<table width="550" border="0"  align="center" cellpadding="5" cellspacing="1" class="detailTable">
    <tr id="infoTableHeader"> 
        <td colspan="3">Ordered Item</td>
    </tr>
    <tr align="center" class="label"> 
        <td>Item</td>
        <td>Unit Price</td>
        <td>Total</td>
    </tr>
    <?php
$numItem  = count($orderedItem);
$subTotal = 0;
for ($i = 0; $i < $numItem; $i++) {
	extract($orderedItem[$i]);
	$subTotal += $od_price;
?>
    <tr class="content"> 
        <td><?php echo "$product_name"; ?></td>
        <td align="right"><?php echo $od_price; ?> CREDITS</td>
        <td align="right"><?php echo $od_price; ?> CREDITS</td>
    </tr>
    <?php
}
?>
    <tr class="content"> 
        <td colspan="2" align="right">Total</td>
        <td align="right"><?php echo $subTotal; ?> CREDITS</td>
    </tr>
</table>
<?php
// get order information
$sql = "SELECT * FROM " . TBL_USERDATA . " WHERE userkey = '$od_shipping_userkey'";
$result = execute_query($sql);
extract($result[0]);
?>
<p>&nbsp;</p>
<table width="550" border="0"  align="center" cellpadding="5" cellspacing="1" class="detailTable">
    <tr id="infoTableHeader"> 
        <td colspan="2">Shipping Information</td>
    </tr>
    <tr> 
        <td width="150" class="label">First Name</td>
        <td class="content"><?php echo $surname; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Last Name</td>
        <td class="content"><?php echo $name; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Address</td>
        <td class="content"><?php echo $address; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Phone Number</td>
        <td class="content"><?php echo $telno; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Province / State</td>
        <td class="content"><?php echo $state; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">City</td>
        <td class="content"><?php echo $city; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Postal Code</td>
        <td class="content"><?php echo $postcode; ?> </td>
    </tr>
</table>
<p>&nbsp;</p>
<table width="550" border="0"  align="center" cellpadding="5" cellspacing="1" class="detailTable">
    <tr id="infoTableHeader"> 
        <td colspan="2">Payment Information</td>
    </tr>
    <tr> 
        <td width="150" class="label">First Name</td>
        <td class="content"><?php echo $surname; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Last Name</td>
        <td class="content"><?php echo $name; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Address</td>
        <td class="content"><?php echo $address; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Phone Number</td>
        <td class="content"><?php echo $telno; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Province / State</td>
        <td class="content"><?php echo $state; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">City</td>
        <td class="content"><?php echo $city; ?> </td>
    </tr>
    <tr> 
        <td width="150" class="label">Postal Code</td>
        <td class="content"><?php echo $postcode; ?> </td>
    </tr>
</table>
<p>&nbsp;</p>
<p align="center"> 
    <input name="btnBack" type="button" id="btnBack" value="Back" class="box" onClick="window.history.back();">
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
